package me.shibor.study.servlet.loginDemo;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 登录操作
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		System.out.println("登录");
		
		String user = request.getParameter("user");
		String password = request.getParameter("password");
	
		System.out.println("user: " + user);
		System.out.println("password: " + password);
		
		if("shibor".equals(user) && "123".equals(password)) {
			HttpSession session = request.getSession();
			session.setAttribute("user", user);
			System.out.println("登录成功");
			request.getRequestDispatcher("/login/success.jsp").forward(request, response);
		}else {
			request.getRequestDispatcher("/login/fail.jsp").forward(request, response);
		}
		
		
	}

}
